//
//  UIButton+ActionInterval.m
//  homework
//
//  Created by huixiubao on 15/7/26.
//  Copyright (c) 2015年 Baidu. All rights reserved.
//

#import "UIButton+ActionInterval.h"

@implementation UIButton (ActionInterval)

- (void)actionWithSelectorString:(NSString *)actionName target:(NSObject *)target delay:(CGFloat)time{
    
    if (self.userInteractionEnabled) {
        SEL actionSelector = NSSelectorFromString(actionName);
        NSMethodSignature *methodSignature = [target methodSignatureForSelector:actionSelector];
        NSInvocation *invocation = nil;
        if (methodSignature) {
            invocation= [NSInvocation invocationWithMethodSignature:methodSignature];
            [invocation setTarget:target];
            [invocation setSelector:actionSelector];
            [invocation invoke];
            self.userInteractionEnabled = NO;
        }
        
        SEL enableSelector = NSSelectorFromString(@"enableSetUserInteraction");
        if ([self respondsToSelector:enableSelector]) {
            [self performSelector:enableSelector withObject:nil afterDelay:time];
        }
    }
}
- (void)enableSetUserInteraction{
    self.userInteractionEnabled = YES;
}

@end
